package db.op.web;

import db.DBUtils;
import functions.web.Register;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import utils.EncryUtils;

/**
 *
 * @author meluo
 * @data 2016/2/16
 */
public class RegisterOP extends DBUtils {

    private Register register;

    public RegisterOP(Register register) {
        this.register = register;
    }
    public Map<String,Object> op(){
         Map<String,Object> map=new HashMap<String,Object>();
        try {
           
            String user_key=EncryUtils.md5(register.getUserEmail());
            String sql ="INSERT INTO testcrash.users (user_key, user_email, user_password) VALUES (?, ?, ?)";
            PreparedStatement prp= getConnection().prepareStatement(sql);
            prp.setString(1,user_key);
            prp.setString(2,register.getUserEmail());
            prp.setString(3, register.getPassword());
            int ret= prepareExecuteUpdate(prp);
            if(ret==1){
                
               map.put("status",true);
               map.put("userKey",user_key);
            }else{
                map.put("struts",false);
            }
           
        } catch (SQLException ex) {
            Logger.getLogger(RegisterOP.class.getName()).log(Level.SEVERE, null, ex);
             map.put("status",false);
        }
         return map;
    }
    
}
